<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>登录页</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
    <script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
    <script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
</head>
<body>
错误信息：<h4 id="errMsg" th:text="${msg}"></h4>
<form>
    <p>账号：<input name="username" type="text" id="username"/></p>
    <p>密码：<input name="password" type="password" id="password"/></p>
    <p><input type="button" id="ajaxLogin" value="登录" /></p>
</form>
</body>
<script type="text/javascript">

    $("#ajaxLogin").click(function() {
        var username = $("#username").val();
        var password = $("#password").val();
        console.log("username:"+username);
        $.post("/login", {
            "username" : username,
            "password" : password
        }, function(result) {
            console.log("result code="+result.code);
            if (result.code == 200) {
                location.href = "/index";
            } else {
                $("#errMsg").html(result.message);
            }
        });
    });
</script>
</html>